#pragma once

#include <string>
#include <vector>
#include <memory>
#include <functional>

class EventLoop;
class EventLoopThread;

class EvenLoopThreadPool{

public:
    using ThreadInitCallback = std::function<void(EventLoop*)>;

    EvenLoopThreadPool(EventLoop* baseLoop, const std::string& name);
    ~EvenLoopThreadPool();

    void setThreadNum(int num){ numThreads_ = num;}

    void start(const ThreadInitCallback &cb = ThreadInitCallback());

    EventLoop* getNextLoop();

    std::vector<EventLoop*> getAllLoops();
    const std::string name() const {return name_;}


private:

    //mainLoop, 如果workLoop的数量为0，则也同时充当workLoop
    EventLoop *bashLoop_; 
    
    std::string name_;
    bool started_;
    int numThreads_;

    // 用于返回轮训是第n个线程
    int next_;

    // 存放线程池的threads 和 每个线程对应的loop
    std::vector<std::unique_ptr<EventLoopThread>> threads_;
    std::vector<EventLoop*> loops_;

};